package com.socialbank.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.socialbank.web.FinanceBean.BankFund;
import com.socialbank.web.bean.ResultMessage;
import com.socialbank.web.service.FundService;

@Controller
@RequestMapping("/bank/fund")
public class BankFundController {
	
	@Resource
	private FundService fundService;
	
	@RequestMapping("/save")
	@ResponseBody
	protected Object save(MultipartFile file){
		fundService.save(file);
		return new ResultMessage(200,"",null);
	} 
	@RequestMapping("/findById")
	@ResponseBody
	protected Object findById(String id,HttpServletRequest request,HttpServletResponse response){
		BankFund fund=fundService.findById(id);
		System.out.println(fund.toString());
		Map<String,Object> result=new HashMap<String,Object>();
		result.put("data", fund);
		return new ResultMessage(200,"",result);
	} 
	
	@RequestMapping("/getList")
	@ResponseBody
	protected Object getList(String fundType){
		List<BankFund> funds=new ArrayList<BankFund>();
		funds=fundService.getList(fundType);
		Map<String,Object> result=new HashMap<String,Object>();
		result.put("data", funds);
		return new ResultMessage(200,"",result);
	} 
	@RequestMapping("/deleteById")
	@ResponseBody
	protected Object deleteById(String id){
		return fundService.deleteById(id);
	} 

}
